#!/usr/bin/python3
# -*- coding:utf-8 -*-

from urllib.request import urlopen
import re

url="http://quotes.toscrape.com/"

url_response = urlopen(url)

# print(url_response)
# print(url_response.getcode())
# print(url_response.geturl())
# print(url_response.info())

url_html = url_response.read()
url_html = url_html.decode("utf-8")
# print(url_html)

quate_list= re.findall('<span class="text" itemprop="text">(.*?)</span>', url_html)
# print(quate_list)
for i in range(len(quate_list)):
    quate_list[i] = quate_list[i].strip("“.”")


author_list=re.findall('<small class="author" itemprop="author">(.*?)</small>', url_html)
# for author in author_list:
#     print(author)
print("------------------tags-------------------------")
tags_list=[]
tags_list_temp=re.findall('<div class="tags">(.*?)</div>', url_html, re.RegexFlag.DOTALL)
for tags in tags_list_temp:
    tag_list = re.findall('<a class="tag" href="(.*?)">(.*?)</a>', tags)
    one_tag_list = []
    for tag in tag_list:
        one_tag_list.append(tag[1])
    one_tag_str=",".join(one_tag_list)
    tags_list.append(one_tag_str)


for i in range(len(tags_list)):
    print("\t".join([quate_list[i], author_list[i], tags_list[i]]))